<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Search_model extends CI_Model {

	var $title   = '';
	var $content = '';
	var $date    = '';

	function __construct()
	{ 
		parent::__construct();
	}
 
	function get_all_answer($num,$offset)
	{
		$this->load->database();
		$query = $this->db->get('tbl_answer',$num,$offset);
		if ($query->num_rows() > 0)
		{
			return $query->result();
		} else {
			return array();
		} 
	}
	
	public function get_answer_by_questionid($question_id,$num,$offset){
		$this->load->database();
		$this->db->where('question_id',$question_id);
		$query = $this->db->get('tbl_answer',$num,$offset);
		if ($query->num_rows() > 0)
		{
			return $query->result();
		} else {
			return array();
		} 
	}

	function total_answer(){
		$this->load->database();
		return $this->db->count_all('tbl_answer'); 
	}
	function delete_answer($id)
	{
		$this->load->database();
		$this->db->delete('tbl_answer', array('id' => $id));
	}

	function insert_answer($question_id,$answer_content)
	{
		$this->load->database();
		$data = array(
			'question_id' => $question_id ,                
			'datecreate' =>  date("Y-m-d H:i:s"),
        	'status' => 0,
        	'answer_content' => $answer_content 
		);
		$this->db->insert('tbl_answer', $data);
	}
	 
}